package list数据结构;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;

public class listDemo {
    public static void main(String[] args) {
        //创建arraylist集合
        ArrayList<String>array=new ArrayList<String>();
        array.add("hello");
        array.add("world");
        array.add("java");

        //普通for循环
        for (int i = 0; i < array.size() ; i++) {
            String s = array.get(i);
            System.out.println(s);
        }

        //迭代器方式
        ListIterator<String> lit = array.listIterator();
        while(lit.hasNext()){
            String s = lit.next();
            System.out.println(s);
        }

        //增强for循环
        for(String s:array){
            System.out.println(s);
        }

        LinkedList<String>linkedList=new LinkedList<>();
        linkedList.add("hello");
        linkedList.add("world");
        linkedList.add("java");

        //普通for循环
        for (int i = 0; i < linkedList.size() ; i++) {
            String s = linkedList.get(i);
            System.out.println(s);
        }

        //迭代器方式
        ListIterator<String> list = linkedList.listIterator();
        while(list.hasNext()){
            String s = list.next();
            System.out.println(s);
        }

        //增强for循环
        for(String s:linkedList){
            System.out.println(s);
        }

    }
}
